/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    id 'java-library'
    id 'java'
}

group = 'at.ac.tuwien.infosys.dslab'
version = '2021'

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
    implementation files('lib/commons-logging-1.2.jar')
    implementation files('lib/hamcrest-core-1.3.jar')
    implementation files('lib/junit-4.12.jar')
    implementation files('lib/orvell-core-0.2.0.jar')
}

// ======== run specifications

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

def dslabRunTasks = [
    [name: 'run-monitoring', main: 'dslab.monitoring.MonitoringServer', args: 'monitoring', description: 'Run Monitoring Server'],
    [name: 'run-transfer-1', main: 'dslab.transfer.TransferServer', args: 'transfer-1', description: 'Run Transfer Server #1'],
    [name: 'run-transfer-2', main: 'dslab.transfer.TransferServer', args: 'transfer-2', description: 'Run Transfer Server #2'],
    [name: 'run-mailbox-earth-planet', main: 'dslab.mailbox.MailboxServer', args: 'mailbox-earth-planet', description: 'Run Mailbox Server for earth.planet'],
    [name: 'run-mailbox-univer-ze', main: 'dslab.mailbox.MailboxServer', args: 'mailbox-univer-ze', description: 'Run Mailbox Server for univer.ze'],
    // assignment 2
    [name: 'run-ns-root', main: 'dslab.nameserver.Nameserver', args: 'ns-root', description: 'Run root nameserver'],
    [name: 'run-ns-ze', main: 'dslab.nameserver.Nameserver', args: 'ns-ze', description: 'Run .ze nameserver'],
    [name: 'run-ns-planet', main: 'dslab.nameserver.Nameserver', args: 'ns-planet', description: 'Run .planet nameserver'],
    [name: 'run-ns-earth-planet', main: 'dslab.nameserver.Nameserver', args: 'ns-earth-planet', description: 'Run .earth.planet nameserver'],
    [name: 'run-client-trillian', main: 'dslab.client.MessageClient', args: 'client-trillian', description: 'Run client for trillian'],
    [name: 'run-client-arthur', main: 'dslab.client.MessageClient', args: 'client-arthur', description: 'Run client for arthur'],
    [name: 'run-client-zaphod', main: 'dslab.client.MessageClient', args: 'client-zaphod', description: 'Run client for zaphod'],
]

// dynamically create run tasks of this structure:
//
// task 'run-transfer-1'(dependsOn: 'classes', type: JavaExec) {
//    main = 'dslab.transfer.TransferServer'
//    args 'transfer-2'
//    classpath = sourceSets.main.runtimeClasspath
//    standardInput = System.in
// }

for (t in dslabRunTasks) {
    def taskName = t['name']

    task "$taskName"(dependsOn: 'classes', type: JavaExec) {
        main = t['main']
        args t['args']
        description = t['description']

        classpath = sourceSets.main.runtimeClasspath
        // https://discuss.gradle.org/t/why-doesnt-system-in-read-block-when-im-using-gradle/3308
        standardInput = System.in
    }
}
